package com.beiding.pojo;

import com.google.common.collect.Sets;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.Assert;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Calendar;
import java.util.Set;

@Getter
@Setter
public class Price {


    public static final Set<Integer> ALLOWED_TIME_UNITS = Sets.newHashSet(Calendar.HOUR, Calendar.DAY_OF_MONTH, Calendar.MONTH, Calendar.YEAR);

    private int serial;

    private float price;
    private int timeUnit;
    private int num;


    //押金
    private float deposit;

    public void setDeposit(float deposit) {
        this.deposit = new BigDecimal(deposit).setScale(2, RoundingMode.FLOOR).floatValue();
    }

    private String text;

    //小数点后两位有效,多余的部分将被舍弃
    public void setPrice(double price) {
        this.price = new BigDecimal(price).setScale(2, RoundingMode.FLOOR).floatValue();
    }

    public void setTimeUnit(int timeUnit) {
        Assert.isTrue(ALLOWED_TIME_UNITS.contains(timeUnit), "时间单位必须是10(小时)、5(天)、2(月)或1(年)中的其中其中一个");
        this.timeUnit = timeUnit;
    }


    @Override
    public String toString() {
        return getText();
    }

}
